#include "database.h"
#include <QDebug>
#include <QMessageBox>
#include <iostream>
#include <QDebug>

Database::Database()
{

}

bool Database::connDataPult()
{
    db = QSqlDatabase::addDatabase("QMYSQL");
    db.setDatabaseName("apulti");
    db.setHostName("localhost");
    db.setUserName("root");
    db.setPassword("root");
    db.setPort(3306);

    if(!db.open())
    {
       qDebug()<<("Failed to open Database");
       return false;
    }
    else
    {
        qDebug()<<("Connected localhost");
        return true;
    }
}

void Database::discData()
{
    QString connection;
    connection=db.connectionName();
    db.close();
    db=QSqlDatabase();
    db.removeDatabase(connection);
    db.removeDatabase(QSqlDatabase::defaultConnection);
    qDebug()<<("Disc.....");
}

bool Database::listAthleteLoad()
{
    db = QSqlDatabase::addDatabase("QMYSQL");
    db.setDatabaseName("sportb");
    db.setHostName("localhost");
    db.setUserName("root");
    db.setPassword("root");
    db.setPort(3306);

    if(!db.open())
    {
       qDebug()<<("Failed to open Database");
       return false;
    }
    else
    {
        qDebug()<<("Connected sportb");
        return true;
    }

}

bool Database::listAthleteLoadHost(QString host)
{
    db = QSqlDatabase::addDatabase("QMYSQL");
    db.setDatabaseName("sportb");
    db.setHostName(host);
    db.setUserName("root");
    db.setPassword("root");
    db.setPort(3306);

    if(!db.open())
    {
       qDebug()<<("Failed to open Database");
       return false;
    }
    else
    {
        qDebug()<<("Connected sportb");
        return true;
    }

}
